<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="https://zhudunfeng.github.io" id="form">
    用户名: <input type="text" name="user"/>
    <hr />
    <input type="checkbox" name="copyright" />接受协议
    <hr />
    <button>提交</button>
  </form>
  
</body>
<script>
  function query(el){
    return document.querySelector(el);
  }

  //添加提交事件
  query("#form").addEventListener("submit",function(event){
    let user=query("[name='user']").value.trim();
    let copyright=query("[name='copyright']").checked;
    
    //当用户为空或者没同意协议，不进行跳转
    if(!user || copyright===false){
      //阻止跳转的默认行为
      event.preventDefault();
      alert("请接受协议并添加用户名");
    }

  });

</script>
</html>